<template>
	<view class="page-body " :class="[app.setCStyle()]">
		<u-navbar :is-back="true" title="我的团队"></u-navbar>
		<view v-if="parent.user_id" class="sj">
			<u-card title="我的上级" sub-title="" margin="0" padding="20">
				<view class="" slot="body">
					<view class="u-flex u-border-bottom u-col-between p20">
						<u-image :width="100" :height="100" shape="circle"  :src="parent.headimgurl?baseUrl+parent.headimgurl:'/static/public/images/headimgurl.jpg'" mode="scaleToFill"></u-image>
						<view class="u-flex-1 u-m-l-40">
							<view class="mt10 u-font-24">{{parent.nick_name}}</view>
							<view class="mt10 u-font-28">用户ID:{{parent.user_id}}</view>
							<view class="mt10 u-font-24">手机号:{{parent.mobile}}</view>
						</view>
					</view>
				</view>
			</u-card>
		</view>
		<view class="main-box  base-select mt20">
			<view class="navbar">
				<view class="nav-item" :class="{current: tabCurrentIndex === 0}" @click="tabClick(0)">直推下级</view>
				<view class="nav-item" :class="{current: tabCurrentIndex === 1}" @click="tabClick(1)">间推下级</view>
			</view>

			<swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
				<swiper-item class="tab-content">
					<view class="p20 bg-white">
						<block  v-for="(uItem, uIndex) in directList">
							<view class="u-flex u-border-bottom u-col-between p20">
								<u-image :width="100" shape="circle" :height="100" :src="uItem.headimgurl?baseUrl+uItem.headimgurl:'/static/public/images/headimgurl.jpg'" mode="scaleToFill"></u-image>
								<view class="u-flex-1  u-m-l-40">
									<view class="mt10 u-font-28">{{uItem.nick_name}}</view>
									<view class="mt10 u-font-24 grey">用户ID:{{uItem.user_id}}</view>
									<view class="mt10 u-font-24 grey">手机号:{{uItem.mobile}}</view>
								</view>
							</view>
						</block>
					</view>
				</swiper-item>
				<swiper-item class="tab-content">
					<view class="p20 bg-white">
						<block  v-for="(uItem, uIndex) in indirectList">
							<view class="u-flex u-border-bottom u-col-between p20">
								<u-image :width="100" shape="circle" :height="100" :src="uItem.headimgurl?baseUrl+uItem.headimgurl:'/static/public/images/headimgurl.jpg'" mode="scaleToFill"></u-image>
								<view class="u-flex-1 u-m-l-40">
									<view class="mt10 u-font-28">{{uItem.nick_name}}</view>
									<view class="mt10 u-font-24 grey">用户ID:{{uItem.user_id}}</view>
									<view  class="mt10 u-font-24 grey">手机号:{{uItem.mobile}}</view>
								</view>
							</view>
						</block>
					</view>
				</swiper-item>
			</swiper>

		</view>
	</view>
</template>

<script>
	import tempSub from '@/pages/member/team/tempSub';
	export default {
		components: {
			tempSub
		},
		data() {
			return {
				baseUrl: this.config.baseUrl,
				tabCurrentIndex: 0,
				directList: {}, //直推
				indirectList: {}, //间推
				teamCount: 0,
				underUserlist: {},
				parent:{}
			}
		},
		onLoad(options) {
			if (typeof(options.tabCurrentIndex) != 'undefined') {
				this.tabCurrentIndex = options.tabCurrentIndex;
			}
			//this.getTeamCount(); //默认获取直推
			this.getUserList(); //默认获取直推
			this.getParent(); 
		},
		methods: {
			//顶部tab点击
			tabClick(index) {
				this.tabCurrentIndex = index;
				this.getUserList();
			},
			//swiper 切换
			changeTab(e) {
				this.tabCurrentIndex = e.target.current;
				//this.getTeamCount();
			},
			collapseChange() { //查看列表
				this.getUserList();
			},
			getUserList() {
				let that = this;
				if (this.tabCurrentIndex == 0) { //直推
					if (that.directList.length > 0) {
						this.$forceUpdate()
						return false;
					}
					this.$u.post('member/api.team/getTeamList', {
						type: 'direct'
					}).then(res => {
						that.directList = res.data;
					})
				} else if (this.tabCurrentIndex == 1) { //间推
					if (that.indirectList.length > 0) {
						this.$forceUpdate()
						return false;
					}
					this.$u.post('member/api.team/getTeamList', {
						type: 'indirect'
					}).then(res => {
						that.indirectList = res.data;
					})
				}
			},
			getParent() {
				let that = this;
				this.$u.post('member/api.team/getParentUser', {}).then(res => {
					that.parent = res.data;
				})
			}
		}
	}
</script>

<style lang="scss">
	.main-box {
		height: calc(100% - 80rpx);
	}

	.swiper-box {
		height: calc(100% - 40rpx);
	}

	.tab-content {
		overflow-y: auto;
	}

	.collapse_item {
		display: block;
		position: relative;
		width: 100%;
		padding: 0 20rpx;
		background-color: #ffffff;
		margin-bottom: 20rpx;
		box-shadow: 0px 10rpx 20rpx 0px rgba(0, 0, 0, 0.04);
		border-radius: 0px 0px 10rpx 10rpx;

		.title {
			line-height: 100rpx;
			color: $font-color-dark;
			font-size: 28rpx;

			.count {
				color: $font-color-dark;
				font-size: 28rpx;
				margin-left: 5rpx;
			}
		}
	}
	.grey{
		color: #666666;
	}

	.user_box {

		.user_item {
			height: 100rpx;
			line-height: 100rpx;

			.img {
				float: left;
				margin-right: 10rpx;
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
			}

		}
	}

	.team-tree {

		.all-title {
			position: relative;
			width: 100%;
			padding: 0 20rpx;
			background-color: #ffffff;
			margin-bottom: 20rpx;
			box-shadow: 0px 10rpx 20rpx 0px rgba(0, 0, 0, 0.04);
			border-radius: 0px 0px 10rpx 10rpx;
			line-height: 100rpx;
			color: $font-color-dark;
			font-size: 28rpx;

			.count {
				color: #98979a;
				font-size: 28rpx;
				margin-left: 5rpx;
			}

			.icon {
				float: right;
				color: rgb(144, 147, 153);
				font-size: inherit;
			}
		}
	}
</style>
